<?php

/**
 * @author shadow245
 * @copyright 2013
 */

class Request {
    private $_project;
    private $_controlador;
    private $_module;
    private $_metodo;
    private $_argumentos;
    private $_config;
    
    public function __construct() {
        if(isset($_GET['url'])){
            $url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL);
            $url = explode('/', $url);
            $url = array_filter($url);
            $this->_module = strtolower(array_shift($url));
            $this->_controlador = strtolower(array_shift($url));
            $this->_metodo = strtolower(array_shift($url));
            $this->_argumentos = $url;
        }       
        
        if(!$this->_module){
            $this->_module = 'index';
        }
        
        if(!$this->_controlador){
            $this->_controlador = DEFAULT_CONTROLLER;
        }
        
        if(!$this->_metodo){
            $this->_metodo = 'index';
        }
        
        if(!isset($this->_argumentos)){
            $this->_argumentos = array();
        }
        
        $rutaCF = ROOT . $this->_module . DS . 'config.php';
        
        if(is_readable($rutaCF)){
            require_once $rutaCF;
            $clase = $this->_module."_cf";
            $this->_config = new $clase;
        }else{
            $this->_config = new Config();
        }
        
    }
    
    public function getModule()
    {
        return $this->_module;
    }
    
    public function getControlador()
    {
        return $this->_controlador;
    }
    
    public function getConfig()
    {
        return $this->_config->config;
    }
    
    public function getMetodo()
    {
        return $this->_metodo;
    }
    
    public function getArgs()
    {
        return $this->_argumentos;
    }
}

?>